//
//  EFengshareCommentsView.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/2/29.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengshareCommentsView.h"
#import "EFengCommentsFrame.h"
#import "NSString+CBExtension.h"
#import "EFengContent.h"
#import "EFShareCommentButton.h"
#import "WZAttrbuteLabel.h"

@implementation EFengshareCommentsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = ClearColor;
    }
    return self;
}

- (void)setCommentsFrame:(EFengCommentsFrame *)commentsFrame
{
    _commentsFrame = commentsFrame;
    
    __block EFengshareCommentsView *weakSelf = self;
    
    self.frame = commentsFrame.frame;
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGSize maxSize = CGSizeMake(commentsFrame.width, MAXFLOAT);
    CGFloat width = commentsFrame.width;
    __block CGSize attrsize;
    __block CGFloat x = 5.0f;
    __block CGFloat y = 0.0f;
    [commentsFrame.commentsArray enumerateObjectsUsingBlock:^(EFengContent *obj, NSUInteger idx, BOOL *stop) {
        WZAttrbuteLabel *label = [[WZAttrbuteLabel alloc] init];
                
        [label setLabeClickAction:^{
            if (weakSelf.eFengshareCommentsViewDelegate != nil && [weakSelf.eFengshareCommentsViewDelegate respondsToSelector:@selector(eFengshareCommentsViewDidHuifuWithComment:)]) {
                [weakSelf.eFengshareCommentsViewDelegate eFengshareCommentsViewDidHuifuWithComment:obj];
            }

        }];
        attrsize = [obj.contentAttr boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;
        label.pasteStr = obj.content;
        [label setAttributedText:obj.contentAttr];
        label.font = Font14;
        label.numberOfLines = 0;
        [self addSubview:label];
        if (idx == 0) {
            label.frame = CGRectMake(x, y, width, (ceilf(attrsize.height)));
        } else {
            UIButton *oldLabel = self.subviews[idx-1];
            label.frame = CGRectMake(x, CGRectGetMaxY(oldLabel.frame) + 5.0f, width, (ceilf(attrsize.height)));
        }
    }];
}



@end
